package com.ruoyi.project.module.yaopin.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.yaopin.domain.Yaopin;
import com.ruoyi.project.module.yaopin.service.IYaopinService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 药品 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-22
 */
@Controller
@RequestMapping("/module/yaopin")
public class YaopinController extends BaseController
{
    private String prefix = "module/yaopin";
	
	@Autowired
	private IYaopinService yaopinService;
	
	@RequiresPermissions("module:yaopin:view")
	@GetMapping()
	public String yaopin()
	{
	    return prefix + "/yaopin";
	}
	
	/**
	 * 查询药品列表
	 */
	@RequiresPermissions("module:yaopin:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Yaopin yaopin)
	{
		startPage();
        List<Yaopin> list = yaopinService.selectYaopinList(yaopin);
		return getDataTable(list);
	}
	
	/**
	 * 新增药品
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存药品
	 */
	@RequiresPermissions("module:yaopin:add")
	@Log(title = "药品", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Yaopin yaopin)
	{		
		return toAjax(yaopinService.insertYaopin(yaopin));
	}

	/**
	 * 修改药品
	 */
	@GetMapping("/edit/{yaoId}")
	public String edit(@PathVariable("yaoId") Integer yaoId, ModelMap mmap)
	{
		Yaopin yaopin = yaopinService.selectYaopinById(yaoId);
		mmap.put("yaopin", yaopin);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存药品
	 */
	@RequiresPermissions("module:yaopin:edit")
	@Log(title = "药品", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Yaopin yaopin)
	{		
		return toAjax(yaopinService.updateYaopin(yaopin));
	}
	
	/**
	 * 删除药品
	 */
	@RequiresPermissions("module:yaopin:remove")
	@Log(title = "药品", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(yaopinService.deleteYaopinByIds(ids));
	}
	
}
